package com.xu.cloud.auth.controller;

import com.xu.cloud.auth.pojo.http.*;
import com.xu.cloud.auth.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 登录 controller
 *
 * @author xuguan
 * @since 2025/2/23
 */
@RestController
@RequestMapping("/api/open/login/v1")
@Validated
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 密码登录
     */
    @PostMapping("/passwordLogin")
    public LoginResp passwordLogin(@Valid PasswordLoginReq req) {
        return loginService.passwordLogin(req);
    }

    /**
     * token登录
     */
    @PostMapping("/tokenLogin")
    public LoginResp tokenLogin(@Valid TokenLoginReq req) {
        return loginService.tokenLogin(req.getAccessToken());
    }

    /**
     * 短信验证码登录
     */
    @PostMapping("/messageCodeLogin")
    public LoginResp messageCodeLogin(@Valid MessageCodeLoginReq req) {
        return loginService.messageCodeLogin(req);
    }

    /**
     * 三方登录
     */
    @PostMapping("/thirdPartyLogin")
    public LoginResp thirdPartyLogin(@Valid ThirdPartyLoginReq req) {
        return loginService.thirdPartyLogin(req);
    }
}
